package com.example.pathprotectsystem.service.impl;

import com.example.pathprotectsystem.mapper.BindMapper;
import com.example.pathprotectsystem.mapper.PathMapper;
import com.example.pathprotectsystem.mapper.RecordMapper;
import com.example.pathprotectsystem.mapper.ResultMapper;
import com.example.pathprotectsystem.pojo.AskList;
import com.example.pathprotectsystem.pojo.BindModel;
import com.example.pathprotectsystem.pojo.PageBean;
import com.example.pathprotectsystem.pojo.SheetModel;
import com.example.pathprotectsystem.service.BindService;
import com.example.pathprotectsystem.service.RecordService;
import com.example.pathprotectsystem.service.ResultService;
import com.example.pathprotectsystem.utils.LiQingCalculateUtil;
import com.example.pathprotectsystem.utils.ShuiniCalculateUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ResultServiceImpl implements ResultService {
    @Autowired
    private ResultMapper resultMapper;
    @Autowired
    private BindMapper bindMapper;
    @Autowired
    private PathMapper pathMapper;
    @Override
    public PageBean<BindModel> usertasklist(AskList askList) {
        //创建PageBean对象
        PageBean<BindModel> pb = new PageBean<>();
        Integer pageNum = askList.getPageNum();
        Integer pageSize = askList.getPageSize();
        String str = askList.getStr();
        int id = askList.getId();
        //开启分页查询 ,PageHelper是个插件
        PageHelper.startPage(pageNum,pageSize);
        List<BindModel> as = resultMapper.usertasklist(str,id);
        System.out.println(as.size());
        //Page中提供了方法，可以获取PageHelper分页查询后  得到的总记录条数和当前页数据
        Page<BindModel> p = (Page<BindModel>) as;
        //把数据填充到PageBean对象中
        pb.setItems(p.getResult());
        pb.setTotal(p.getTotal());
        return pb;
    }

    @Override
    public void addf1(SheetModel sheetModel) {
        resultMapper.addf1(sheetModel);
    }

    @Override
    public void addf2(SheetModel sheetModel) {
        resultMapper.addf2(sheetModel);
    }

    @Override
    public void addf3(SheetModel sheetModel) {
        resultMapper.addf3(sheetModel);
    }

    @Override
    public void addf4(SheetModel sheetModel) {
        int taskId = sheetModel.getId();
        int pathId = bindMapper.getpathid(taskId);
        String pavementType = pathMapper.getpavementType(pathId);
        String damageType = sheetModel.getDamageType();
        double l = sheetModel.getDamageLongth();
        double w = sheetModel.getDamageWidth();
        double h = sheetModel.getDamageHighth();
        if(pavementType.equals("沥青路面")){
            if(damageType.equals("线裂")){
                sheetModel.setDamageArea(LiQingCalculateUtil.xianlie(l,w,h));
            } else if (damageType.equals("网裂")) {
                sheetModel.setDamageArea(LiQingCalculateUtil.wanglie(l,w,h));
            } else if (damageType.equals("龟裂")) {
                sheetModel.setDamageArea(LiQingCalculateUtil.guilie(l,w,h));
            } else if (damageType.equals("拥包")) {
                sheetModel.setDamageArea(LiQingCalculateUtil.yongbao(l,w,h));
            } else if (damageType.equals("车辙")) {
                sheetModel.setDamageArea(LiQingCalculateUtil.chezhe(l,w,h));
            } else if (damageType.equals("沉陷")) {
                sheetModel.setDamageArea(LiQingCalculateUtil.chenxian(l,w,h));
            } else if (damageType.equals("翻浆")) {
                sheetModel.setDamageArea(LiQingCalculateUtil.fanjiang(l,w,h));
            } else if (damageType.equals("剥落")) {
                sheetModel.setDamageArea(LiQingCalculateUtil.boluo(l,w,h));
            } else if (damageType.equals("坑槽")) {
                sheetModel.setDamageArea(LiQingCalculateUtil.kengcao(l,w,h));
            }else if (damageType.equals("啃边")) {
                sheetModel.setDamageArea(LiQingCalculateUtil.kenbian(l,w,h));
            }else if (damageType.equals("路框差")) {
                sheetModel.setDamageArea(LiQingCalculateUtil.lukuangcha(l,w,h));
            }else if (damageType.equals("唧浆")) {
                sheetModel.setDamageArea(LiQingCalculateUtil.jijiang(l,w,h));
            }else if (damageType.equals("泛油")) {
                sheetModel.setDamageArea(LiQingCalculateUtil.fanyou(l,w,h));
            }
        }
        else{
            if(damageType.equals("线裂")){
                sheetModel.setDamageArea(ShuiniCalculateUtil.xianlie(l,w,h));
            } else if (damageType.equals("板角断裂")) {
                sheetModel.setDamageArea(ShuiniCalculateUtil.banjiaoduanlie(l,w,h));
            } else if (damageType.equals("边角裂缝")) {
                sheetModel.setDamageArea(ShuiniCalculateUtil.bianjiaoliefeng(l,w,h));
            } else if (damageType.equals("交叉裂缝和破碎板")) {
                sheetModel.setDamageArea(ShuiniCalculateUtil.jiaochaliefeng(l,w,h));
            } else if (damageType.equals("接缝料损坏")) {
                sheetModel.setDamageArea(ShuiniCalculateUtil.jiefengliaosunhuai(l,w,h));
            } else if (damageType.equals("边角剥落")) {
                sheetModel.setDamageArea(ShuiniCalculateUtil.bianjiaoboluo(l,w,h));
            } else if (damageType.equals("坑洞")) {
                sheetModel.setDamageArea(ShuiniCalculateUtil.kengdong(l,w,h));
            } else if (damageType.equals("表面纹裂")) {
                sheetModel.setDamageArea(ShuiniCalculateUtil.biaomianwenlie(l,w,h));
            } else if (damageType.equals("层状剥落")) {
                sheetModel.setDamageArea(ShuiniCalculateUtil.cengzhuangboluo(l,w,h));
            }else if (damageType.equals("错台")) {
                sheetModel.setDamageArea(ShuiniCalculateUtil.cuotai(l,w,h));
            }else if (damageType.equals("拱胀")) {
                sheetModel.setDamageArea(ShuiniCalculateUtil.gongzhang(l,w,h));
            }else if (damageType.equals("唧浆")) {
                sheetModel.setDamageArea(ShuiniCalculateUtil.jijiang(l,w,h));
            }else if (damageType.equals("路框差")) {
                sheetModel.setDamageArea(ShuiniCalculateUtil.lukuangcha(l,w,h));
            }else if (damageType.equals("沉陷")) {
                sheetModel.setDamageArea(ShuiniCalculateUtil.chenxian(l,w,h));
            }
        }
        resultMapper.addf4(sheetModel);
    }
}
